package com.dunshan.rabbitmq.provider;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author dunshan
 * @program: dunshan-pef
 * @description: test
 * @date 2021-08-29 20:20:11
 */
@SpringBootTest
public class DemoProvider {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Test
    public void ProducerTest() {
        String messageId = String.valueOf(UUID.randomUUID());
        String messageData = "message: 性能测试-线上流量";
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        Map<String, Object> manMap = new HashMap<>();
        manMap.put("messageId", messageId);
        manMap.put("messageData", messageData);
        manMap.put("createTime", createTime);
        rabbitTemplate.convertAndSend("topicExchange", "topic.dunshan", manMap);


    }

    @Test
    public void consumerTest() {
        System.out.println("=====================================\n");
        Object o = rabbitTemplate.receiveAndConvert("topic.dunshan");
        System.out.println("获取结果：" + o);
    }

}
